import { System, World } from '@ecs/index'
import { Rotate } from '../components'

/**
 * 旋转系统
 * @description 计算物体的角运动速度
 */
export class RotateSystem extends System {
  constructor() {
    super()
  }

  public update(world: World): void {
    for (const [, componentMap] of world.view(Rotate)) {
      const rotate = componentMap.get(Rotate)

      rotate.va += rotate.a
      rotate.angle += rotate.va
      if (rotate.angle >= Math.PI / 3) {
        rotate.angle = Math.PI / 3 // 最大角度
      } else if (rotate.angle <= -Math.PI / 3) {
        rotate.angle = -Math.PI / 3 // 最小角度
      }
    }
  }

  public destory(): void {}
}
